from django.db import models

# Create your models here.
class UserInfo(models.Model):
    user_type_choice=(
        (1,"普通用户"),
        (2,"会员")
    )
    user_type=models.IntegerField(choices=user_type_choice)
    user_name=models.CharField(max_length=32,unique=True,choices=user_type_choice)
    password=models.CharField(max_length=64)
    group = models.ForeignKey(to='UserGroup',null=True,blank=True,on_delete=models.CASCADE)
    roles = models.ManyToManyField(to='Role')

    @property
    def user_name_vip(self):
        return self.user_name+"_vip"


class UserToken(models.Model):
    user=models.OneToOneField(to=UserInfo,on_delete=models.CASCADE)
    token=models.CharField(max_length=64)

class UserGroup(models.Model):
    """用户组"""
    name = models.CharField(max_length=32,unique=True)


class Role(models.Model):
    """角色"""
    name = models.CharField(max_length=32,unique=True)
